package com.svms.save.controller;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.svms.save.entitys.SvdaTsgl;
import com.svms.save.services.BookISBNService;
import com.svms.save.vo.ResultVo;

@Controller
@RequestMapping("/book")
public class BookISBNController {
	
	private Logger log = LoggerFactory.getLogger(BookISBNController.class);
	
	@Autowired
	private BookISBNService bookmanager;
	@RequestMapping(value = "/findbook",method = RequestMethod.GET)
	@ResponseBody
	public ResultVo<List<SvdaTsgl>> findBookByISBN(String atServer,String isbn){
		ResultVo<List<SvdaTsgl>> res = null;
		try {
			List<SvdaTsgl> list = bookmanager.findByISBN(atServer, isbn);
			if(null != list) {
				res = ResultVo.success("", list);
			}else {
				res = ResultVo.businessError("未能查找到该图书信息！", "");
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error("系统错误！",e);
			res = ResultVo.systemError("系统发生错误！", "");
		}
		return res;
	}
	@RequestMapping(value = "/doSave")
	@ResponseBody
	public ResultVo<Integer> doSave(@RequestBody List<SvdaTsgl> tsgls){
		ResultVo<Integer> res = null;
		try {
			int r = bookmanager.doSaveTsgl(tsgls);
			if(r > 0) {
				res = ResultVo.success("提交成功！", r);
			}else {
				res = ResultVo.businessError("提交失败！", r);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error("系统错误！",e);
			res = ResultVo.systemError("系统发生错误！", "");
		}
		return res;
	}
}
